<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="AddData">
				<el-form-item label="商品大类">
					<el-input v-model="AddData.General"></el-input>
				</el-form-item>
				<el-form-item label="商品名称">
					<el-input v-model="AddData.name"></el-input>
				</el-form-item>
				<el-form-item label="规格型号">
					<el-input v-model="AddData.model"></el-input>
				</el-form-item>
				<el-form-item label="到货数量">
					<el-input v-model="AddData.num"></el-input>
				</el-form-item>
				<el-form-item label="到货单价">
					<el-input v-model="AddData.Price"></el-input>
				</el-form-item>
				<el-form-item label="厂商">
					<el-input v-model="AddData.manufacturer"></el-input>
				</el-form-item>
				<el-form-item label="到货日期">
					<div class="block">
						<el-date-picker
						v-model="AddData.value2"
						type="date"
						placeholder="选择"
						format="yyyy-MM-dd">
						</el-date-picker>
					</div>
				</el-form-item>
				<el-form-item label="存放位置">
					<el-input v-model="AddData.position"></el-input>
				</el-form-item>
				<el-form-item label="接收人">
					<el-input v-model="AddData.Receiver"></el-input>
				</el-form-item>
				<div>
					<el-form-item label="备注">
						<el-input type="textarea" cols="200" v-model="AddData.remarks"></el-input>
					</el-form-item>
				</div>
				<el-form-item>
					<el-button type="success" icon="el-icon-plus" style="margin-left:40px">新增</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--搜索-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;    background: #fff;">
			<el-form :inline="true" :model="filters">
				<el-form-item label="搜索关键词">
					<el-input v-model="filters.name"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" v-on:click="getUsers">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="users" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection">
			</el-table-column>
			<el-table-column prop="addr" label="商品大类" sortable  align="center">
			</el-table-column>
			<el-table-column prop="addr" label="商品名称" align="center" sortable>
			</el-table-column>
			<el-table-column prop="age" label="规格型号	" align="center" sortable>
			</el-table-column>
			<el-table-column prop="age" label="到货数量"  align="center" sortable >
			</el-table-column>
			<el-table-column prop="age" label="单价" align="center" sortable>
			</el-table-column>
			<el-table-column prop="addr" label="厂商" align="center" sortable>
			</el-table-column>
			<el-table-column prop="birth" label="到货日期" align="center" sortable>
			</el-table-column>
			<el-table-column prop="addr" label="存放位置" align="center" sortable>
			</el-table-column>
			<el-table-column prop="addr" label="接收人" align="center" sortable>
			</el-table-column>
			<el-table-column prop="addr" label="备注" align="center" sortable>
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template slot-scope="scope">
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../api/api';

	export default {
		data() {
			return { 
				AddData:{
					General:'',
					name:'',
					model:'',
					num:'',
					Price:'',
					manufacturer:'',
					value2:'',
					position:'',
					Receiver:'',
					remarks:''
				},
				filters: {
					name: '',
				},
				users: [],
				total: 0,
				page: 1,
				listLoading: false,
				sels: [],//列表选中列

			}
		},
		methods: {
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			//获取用户列表
			getUsers() {
				let para = {
					page: this.page,
					name: this.filters.name
				};
				this.listLoading = true;
				//NProgress.start();
				getUserListPage(para).then((res) => {
					
					this.total = res.data.total;
					this.users = res.data.users;
					console.log(this.users);
					this.listLoading = false;
					//NProgress.done();
				});
			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { id: row.id };
					removeUser(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {

				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
				var ids = this.sels.map(item => item.id).toString();
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { ids: ids };
					batchRemoveUser(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {

				});
			}
		},
		mounted() {
			this.getUsers();
		}
	}

</script>

<style scoped>
</style>